

def startup():
    import os, winshell
    import sys
    import getpass
    from win32com.client import Dispatch
    from  tkinter import  messagebox

    a = os.path.basename(sys.argv[0])  # 获取自身文件名
    d = getpass.getuser()  # 获取用户名
    b = r'C:\\Users'
    b += '\\' + d + '\\' + r'AppData\\Roaming\Microsoft\\Windows\\Start Menu\\Programs\\Startup'
    c = b  # 启动目录
    b += '\\' + a + ".lnk"

    # 获取自身文件名
    my_name = sys.argv[0]  #
    my_patth = os.getcwd()  # 文件路径

    # target = r"D:\New folder\new.exe"  # The shortcut target file or folder
    # path = r"H:\happy\hi\new.lnk"  # Path to be saved (shortcut)
    target = my_name
    path = b

    work_dir = my_patth + "/"
    shell = Dispatch('WScript.Shell')
    shortcut = shell.CreateShortCut(path)
    shortcut.Targetpath = target
    shortcut.WorkingDirectory = work_dir
    shortcut.save()
    print("ok start up")

    #messagebox.showerror('说明','添加自身文件的快捷方式成功了')

